{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "fa81855e",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "* 日期：2023-11-13\n",
    "* 课程：python\n",
    "* week11\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b962624f",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "## 1. 元组\n",
    "> 1. 概念\n",
    "> 2. 创建\n",
    "> 3. 一般方法\n",
    "\n",
    "## 2.集合\n",
    "> 1. 概念\n",
    "> 2. 创建\n",
    "> 3. 一般方法\n",
    "\n",
    "## 3. 字典\n",
    "> 1. 概念\n",
    "> 2. 创建\n",
    "> 3. 一般方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "39d72dcb",
   "metadata": {},
   "source": [
    "# 1.元组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "24044759",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1699873720.3954637"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import time\n",
    "time.time ()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4b2352d4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1.1 元组的创建方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e4eb0be4",
   "metadata": {},
   "outputs": [],
   "source": [
    "my_tuple1 = 1699873684,100001,\"小明\",18,\"冰岛\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d6038b31",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1699873684, 100001, '小明', 18, '冰岛')\n",
      "<class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "print(my_tuple1)\n",
    "print(type(my_tuple1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "db57263d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(699873684, 100001, '小明', 18, '冰岛')\n",
      "<class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "my_tuple2 = (699873684,100001,\"小明\",18,\"冰岛\")\n",
    "print(my_tuple2)\n",
    "print(type(my_tuple2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "de214b9e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2.第二种创建元组的方法\n",
    "my_tuple3 = tuple(('Jessa',30,45.75,[89,78]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "ba0c9949",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('Jessa', 30, 45.75, [89, 78])\n",
      "<class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "print(my_tuple3)\n",
    "print(type(my_tuple3))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f757e27b",
   "metadata": {},
   "source": [
    "# 1.2 元组的一般方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5beeac49",
   "metadata": {},
   "source": [
    "* 1. 关于序列数据的一般方法均适用于元组\n",
    "> 1.indexing and slicing （索引取值和切片）\n",
    "> 2.in方法查询\n",
    "> 3. len()\n",
    "> 4. for循环便利\n",
    "\n",
    "* 2. 元组独有的常用方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "834d1c0c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "45.75"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_tuple3[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "cb827d03",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(45.75, [89, 78])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_tuple3[2:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "c4708671",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Jalex' in my_tuple3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "005c8355",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Jessa'in my_tuple3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "99ae7048",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(my_tuple3)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "21318afc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jessa\n",
      "30\n",
      "45.75\n",
      "[89, 78]\n"
     ]
    }
   ],
   "source": [
    "for i in my_tuple3:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "1b71748a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_tuple3.count(45.75)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "ae52bac2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_tuple3.index([89, 78])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "43e14339",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'tuple' object does not support item assignment",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[22], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m my_tuple3[\u001b[38;5;241m0\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mJerry\u001b[39m\u001b[38;5;124m'\u001b[39m\n",
      "\u001b[1;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"
     ]
    }
   ],
   "source": [
    "my_tuple3[0] = 'Jerry'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3b922d65",
   "metadata": {},
   "source": [
    "# 2.集合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "1edb144d",
   "metadata": {},
   "outputs": [],
   "source": [
    "歌剧社 = {'小明','小红','李华','张三'}\n",
    "街舞社 = {'小明','李鹏','王芳'}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "3a374683",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'小明', '小红', '张三', '李华', '李鹏', '王芳'}"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 并集\n",
    "歌剧社.union(街舞社)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "bb085538",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'小红', '张三', '李华'}"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 差集\n",
    "歌剧社.difference(街舞社)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "a4ff254f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'小红', '张三', '李华'}"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "歌剧社 - 街舞社"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "73d9ae41",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'李鹏', '王芳'}"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "街舞社.difference(歌剧社)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "de7219aa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'小红', '张三', '李华', '李鹏', '王芳'}"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 对称差集\n",
    "歌剧社.symmetric_difference(街舞社)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "582d5747",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function symmetric_difference:\n",
      "\n",
      "symmetric_difference(...) method of builtins.set instance\n",
      "    Return the symmetric difference of two sets as a new set.\n",
      "    \n",
      "    (i.e. all elements that are in exactly one of the sets.)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(歌剧社.symmetric_difference)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "65a78647",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'小明'}"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "歌剧社 & 街舞社"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "529fea3a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'小明'}"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#交集： 找出重复的项\n",
    "歌剧社.intersection(街舞社)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "3f849ce2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'小明', '小红', '张三', '李华', '李鹏', '王芳'}"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 运算法则 \n",
    "歌剧社 | 街舞社"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d91345b7",
   "metadata": {},
   "source": [
    "# 3.字典(dict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "48310d35",
   "metadata": {},
   "outputs": [],
   "source": [
    "info = {\n",
    "    \"stu2201\":\"Ziqi\",\n",
    "    \"stu2202\":\"XiaoFeng\",\n",
    "    \"stu2203\":\"Liuyu\",\n",
    "    \n",
    "    \n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "be2946be",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu2201': 'Ziqi', 'stu2202': 'XiaoFeng', 'stu2203': 'Liuyu'}\n",
      "<class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "print(info)\n",
    "print(type(info))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "ebeba512",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'XiaoFeng'"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "info[\"stu2202\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "33418a66",
   "metadata": {},
   "outputs": [],
   "source": [
    " info_01 = {\n",
    "    \"stu2201\":[\"Ziqi\",2200001,18,\"女\"],\n",
    "    \"stu2202\":[\"XiaoFeng\",2200002,20,\"男\"],\n",
    "    \"stu2203\":[\"Liuyu\",2200003,19,\"\"],\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "4f0071f4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['XiaoFeng', 2200002, 20, '男']"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "info_01[\"stu2202\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5dd5e8e2",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
